<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>机具查询</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
   <link rel="stylesheet" href="../../../bangnuo/admin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../bangnuo/admin/style/admin.css" media="all">
  <script src="../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
<!--  <script src="../../../bangnuo/admin/layui/layui.js"></script>-->
</head>
<body>


<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">编号</label>
          <div class="layui-input-block">
            <input type="text" name="terminalNumber" placeholder="请输入" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">SN</label>
          <div class="layui-input-block">
            <input type="text" name="terminalSN" placeholder="请输入" autocomplete="off"
                   class="layui-input">
            <input type="hidden" name="terminalUuid" placeholder="请输入" autocomplete="off"
                   class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
          </button>
        </div>
      </div>
    </div>

    <div class="layui-card-body">
      <div style="padding-bottom: 10px;">
        <button class="layui-btn layuiadmin-btn-useradmin" onclick="addadmin()">添加器具</button>
      </div>

      <table id="admin-demo" lay-data="" data-value="{{}}" lay-filter="admin-demo"></table>

      <script type="text/html" id="imgTpl">
        <img style="display: inline-block; width: 50%; height: 100%;" src={ { d.avatar }}>
      </script>
      <script type="text/html" id="table-useradmin-webuser">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                class="layui-icon layui-icon-edit"></i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                class="layui-icon layui-icon-delete"></i>删除</a>
      </script>
    </div>
  </div>
</div>

</body>
<script src="../../../bangnuo/admin/layui/layui.js"></script>
<script type="text/javascript" src="../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>

<script type="text/javascript">
    function addadmin() {
        layui.use("table", function () {
            var table = layui.table;
            layer.open({
                type: 2,
                title: '新增器具',
                area: ['500px', '600px'],
                content: 'operation/add-machines.html' //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            });
        })
    }
</script>
<!--状态-->
<script src="//res.layui.com/layui/dist/layui.js" charset="utf-8"></script>
<script type="text/html" id="tpl_adminState">
  {{# if(d.terminalState == "1"){ }}
  <b style="color: blue;">正常</b> {{# } else { }} <b style="color: red;">锁定</b> {{# } }}
</script>
<script>
    layui.use(['util', 'table', 'form'], function () {
        var table = layui.table,
            form = layui.form;
        form.on('submit(LAY-user-front-search)', function (data) {
            var adminEntity = {
                "terminalNumber": data.field.terminalNumber,
                "terminalUuid": data.field.terminalUuid,
                "terminalSN": data.field.terminalSN
            };
            table.reload('admin-overloading', {
                url: '/terminalEntity/findListNew2',
                where: adminEntity,
                page:{
                    curr:1
                }
            });
            return false;
        });

        //第一个实例
        table.render({
            elem: '#admin-demo',
            method: "POST",
            contentType: "application/json",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar:
                ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
            title: '用户数据表',
            url: '/terminalEntity/findListNew2', //数据接口
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.queryResult.total, //解析数据长度
                    "data": res.queryResult.list //解析数据列表
                };
            },
            page: true, //开启分页
            limit: 5,
            id: "admin-overloading",
            limits: [5, 10, 20, 50, 100],
            cols: [
                [ //表头
                    /*{
                        type: 'checkbox',
                        fixed: 'left'
                    },*/
                    {
                        field: 'terminalNumber',
                        title: '编号',
                        width: 120,
                        sort: true,
                        fixed: 'left'
                    },
                    {
                        field: 'terminalUuid',
                        title: 'id',
                        width: 120,
                        sort: true,
                        fixed: 'left'
                    }
                    , {
                    field: 'terminalSN',
                    title: 'SN',
                    width: 120
                },  {
                    field: 'shopName',
                    title: '所属门店',
                    width: 150
                }, {
                    field: 'terminalCreateTime',
                    title: '创建时间',
                    width: 160,
                    templet: '<div>{{ layui.util.toDateString(d.terminalCreateTime, "yyyy-MM-dd HH:mm:ss") }}</div>',
                    // sort: true
                }, {
                    field: 'terminalState',
                    title: '状态',
                    width: 80,
                    templet: '#tpl_adminState'
                }, {
                        field: 'terminalName',
                        title: '机具名字',
                        width: 120,
                    }, {
                    fixed: 'right',
                    align: 'center',
                    title: '操作',
                    toolbar: '#table-useradmin-webuser'
                },
                ]
            ]
        });
        table.on('tool(admin-demo)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if (layEvent === 'del') { //删除
                layer.confirm('真的删除行么', function (index) {
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    //向服务端发送删除指令
                    $.ajax({
                        type: "GET",
                        // url: "/adminEntity/delAdmin/" + data.adminUuid,
                        url: "/terminalEntity/delTerminal/" + data.terminalUuid,
                        async: true,
                        success: function (data) {
                            if (data.success == true) {
                                layer.msg("删除成功");
                            } else {
                                layer.msg("删除失败");
                            }
                        }
                    });
                });
            } else if (layEvent === 'edit') { //编辑
                //do something
                //同步更新缓存对应的值
                layer.open({
                    type: 2,
                    title: '修改器具',
                    area: ['500px', '600px'],
                    // content: 'users/edit-shop.html?id=' + data.adminUuid //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    content: 'operation/edit-machines.html?id=' + data.terminalUuid //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
                obj.update({
                    username: '123',
                    title: 'xxx'
                });
            } else if (layEvent === 'LAYTABLE_TIPS') {
                layer.alert('Hi，头部工具栏扩展的右侧图标。');
            }
        });
    });
</script>
</body>
</html>
